package com.cn.kabalifemerchants.view;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.cn.kabalifemerchants.R;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;


/**
 * Created by 晓林 on 2019/11/14.
 * function:
 */
public class NotDataView {
    public static View notDataView(Activity activity, RecyclerView recyclerView, SmartRefreshLayout refreshLayout) {
        View notDataView;
        notDataView = activity.getLayoutInflater().inflate(R.layout.show_empty_view, (ViewGroup) recyclerView.getParent(), false);
        TextView tvTitle = notDataView.findViewById(R.id.tv_net_error);
        tvTitle.setText("暂无数据");
        notDataView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (refreshLayout != null)
                    refreshLayout.autoRefresh();
            }
        });
        return notDataView;
    }

    public static View notDataView(Activity activity, RecyclerView recyclerView, SmartRefreshLayout refreshLayout, String msg) {
        View notDataView;
        notDataView = activity.getLayoutInflater().inflate(R.layout.show_empty_view, (ViewGroup) recyclerView.getParent(), false);
        TextView tvTitle = notDataView.findViewById(R.id.tv_net_error);
        tvTitle.setText(msg);
        notDataView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (refreshLayout != null)
                    refreshLayout.autoRefresh();
            }
        });
        return notDataView;
    }

    public static View notDataView(Activity activity, RecyclerView recyclerView, SmartRefreshLayout refreshLayout, String msg, int imgID) {
        View notDataView;
        notDataView = activity.getLayoutInflater().inflate(R.layout.show_empty_view, (ViewGroup) recyclerView.getParent(), false);
        TextView tvTitle = notDataView.findViewById(R.id.tv_net_error);
        ImageView img = notDataView.findViewById(R.id.img_error);
        img.setImageResource(imgID);
        tvTitle.setText(msg);
        notDataView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (refreshLayout != null)
                    refreshLayout.autoRefresh();
            }
        });
        return notDataView;
    }

    public static View notDataView(Activity activity, RecyclerView recyclerView) {
        View notDataView;
        notDataView = activity.getLayoutInflater().inflate(R.layout.show_empty_view, (ViewGroup) recyclerView.getParent(), false);
        TextView tvTitle = notDataView.findViewById(R.id.tv_net_error);
        tvTitle.setText("暂无数据");
        return notDataView;
    }
}
